package com.xxlie.shop.endpoint;

import com.xxlie.core.model.Page;
import com.xxlie.core.model.Query;
import com.xxlie.core.model.View;
import com.xxlie.shop.domain.Feedback;
import com.xxlie.shop.service.FeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController("apiAdminFeedback")
@RequestMapping("/api/admin/feedback")
public class FeedbackEndpoint {
    @Autowired
    FeedbackService feedbackService;

    /**
     * 获取意见反馈列表
     * @param request
     * @param response
     * @param query
     * @return
     */
    @RequestMapping("/list")
    public View<Page> list(HttpServletRequest request, HttpServletResponse response, @RequestBody Query<Feedback> query) {
        View<Page> view = new View(20000, "获取列表成功");

        Feedback feedback = query.getData();

        Page<Feedback> page = feedbackService.findAll(new Page<>(query.getPage(), query.getSize()), feedback);

        view.setData(page);

        return view;
    }

    /**
     * 删除意见反馈
     * @param request
     * @param response
     * @param id
     * @return
     */
    @RequestMapping("/delete/{id}")
    public View delete(HttpServletRequest request, HttpServletResponse response, @PathVariable("id") Long id) {
        View view = new View(20000, "删除成功");

        this.feedbackService.delete(id);

        return view;
    }
}